package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.SwfDelegate;
	import com.icid.store.event.GetSwfListEvent;
	import com.icid.store.model.SwfModelLocator;
	import com.icid.store.vo.SwfVO;
	
	import mx.rpc.IResponder;

	public class GetSwfListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:SwfDelegate;
		private var getSwfListEvent:GetSwfListEvent;
		private var swfModel:SwfModelLocator = SwfModelLocator.getInstance();
		public function GetSwfListCommand()
		{
			super();
			delegate = new SwfDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getSwfListEvent = GetSwfListEvent(event);
			delegate.read(getSwfListEvent.sid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			swfModel.swfList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var swfVO:SwfVO = new SwfVO();
				
				swfVO.description = data.result[i].description;
				swfVO.id = data.result[i].id;
				swfVO.time = data.result[i].time;
				swfVO.title = data.result[i].title;
				swfVO.url = data.result[i].url;
				
				swfModel.swfList.addItem(swfVO);
			}
			swfModel.swfList.refresh();
		}
		
	}
}